package cate.game.pvp.pointrace.simulator;

import cate.game.pvp.pointrace.timer.PointRaceTimerTask.Settings;

import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;

public class BothPointRaceSimulatorSelector implements PointRaceSimulatorSelector {

    private final List<PointRaceSimulator> simulators;

    public BothPointRaceSimulatorSelector(Supplier<List<PointRaceSimulator>> simulatorsSupplier) {
        Objects.requireNonNull(simulatorsSupplier);
        this.simulators = Objects.requireNonNull(simulatorsSupplier.get());
    }

    @Override
    public PointRaceSimulator select(Settings settings) {
        return this.simulators.stream()
                .filter(simulator -> simulator.isMatch(settings))
                .findFirst()
                .orElse(null);
    }
}
